package com.lill.system.serivce.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.lill.system.dao.ISysUserRoleDao;
import com.lill.system.service.ISysUserRoleService;


/**
 * 用户与角色对应关系
 *
 * @author lill
 */
@Service("sysUserRoleService")
public class SysUserRoleServiceImpl implements ISysUserRoleService {
    @Autowired
    private ISysUserRoleDao sysUserRoleDao;

    public void saveOrUpdate(String userId, List<String> roleIdList) {
        if (roleIdList.size() == 0) {
            return;
        }

        //先删除用户与角色关系
        sysUserRoleDao.delete(userId);

        //保存用户与角色关系
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("userId", userId);
        map.put("roleIdList", roleIdList);
        sysUserRoleDao.save(map);
    }
    public void saveOrUpdates(String userId, List<String> roleIdList) {
        if(roleIdList!=null){
            if (roleIdList.size() == 0) {
                return;
            }

            //先删除用户与角色关系
            sysUserRoleDao.delete(userId);

            //保存用户与角色关系
            Map<String, Object> map = new HashMap<String, Object>();
            map.put("userId", userId);
            map.put("roleIdList", roleIdList);
            sysUserRoleDao.save(map);
        }

    }

    public List<String> queryRoleIdList(String userId) {
        return sysUserRoleDao.queryRoleIdList(userId);
    }

    public void delete(String userId) {
        sysUserRoleDao.delete(userId);
    }
}
